<?php
namespace Biz\model;

use Doraemon\pockets\datebase\BaseDbModel;

class ShopCategoryScene extends BaseDbModel
{
	const _CONFIG_FILE_ = 'db_shop';

	const _CONFIG_SELECT_ = 'db_shop';

	const _DATABASE_ = 'shop';

	const _TABLE_NAME = 'shop_category_scene';


	const STATUS_NORMAL = 1;
	const STATUS_DEL = 0;

	public static function addSceneTags($sceneName, array $categoryNames)
	{
		$categoryNames = array_filter($categoryNames);
		$categoryNames = implode(',', $categoryNames);

		self::insert([
			'scene_name' => $sceneName,
			'categorys_name' => $categoryNames,
			'add_time' => date('Y-m-d H:i:s'),
			'status' => self::STATUS_NORMAL
		]);

		return self::id();
	}

	public static function updateSceneTags($id, $sceneName, array $categoryNames)
	{
		$categoryNames = array_filter($categoryNames);
		$categoryNames = implode(',', $categoryNames);

		return self::update([
			'scene_name' => $sceneName,
			'categorys_name' => $categoryNames,
			'add_time' => date('Y-m-d H:i:s'),
		], [
			'id' => $id
		]) -> rowCount();

	}

	public static function getSceneTags($id = 0)
	{
		if ($id) {
			$sceneTag = self::get('*', ['id' => $id, 'status' => self::STATUS_NORMAL]);
			$sceneTag['categorys_name'] = explode(',', $sceneTag['categorys_name']);
			return $sceneTag;
		} else {
			return self::select('*', ['status' => self::STATUS_NORMAL]);
		}
	}

	public static function del($id)
	{
		return self::update(['status' => self::STATUS_DEL], ['id' => $id]) -> rowCount();
	}

	
}